<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单ID" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder="订单ID"></el-input>
    </el-form-item>
    <el-form-item label="费用规则id" prop="feeRuleId">
      <el-input v-model="dataForm.feeRuleId" placeholder="费用规则id"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="totalAmount">
      <el-input v-model="dataForm.totalAmount" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="应付款金额" prop="payAmount">
      <el-input v-model="dataForm.payAmount" placeholder="应付款金额"></el-input>
    </el-form-item>
    <el-form-item label="里程费" prop="distanceFee">
      <el-input v-model="dataForm.distanceFee" placeholder="里程费"></el-input>
    </el-form-item>
    <el-form-item label="等时费用" prop="waitFee">
      <el-input v-model="dataForm.waitFee" placeholder="等时费用"></el-input>
    </el-form-item>
    <el-form-item label="远程费" prop="longDistanceFee">
      <el-input v-model="dataForm.longDistanceFee" placeholder="远程费"></el-input>
    </el-form-item>
    <el-form-item label="路桥费" prop="tollFee">
      <el-input v-model="dataForm.tollFee" placeholder="路桥费"></el-input>
    </el-form-item>
    <el-form-item label="停车费" prop="parkingFee">
      <el-input v-model="dataForm.parkingFee" placeholder="停车费"></el-input>
    </el-form-item>
    <el-form-item label="其他费用" prop="otherFee">
      <el-input v-model="dataForm.otherFee" placeholder="其他费用"></el-input>
    </el-form-item>
    <el-form-item label="顾客好处费" prop="favourFee">
      <el-input v-model="dataForm.favourFee" placeholder="顾客好处费"></el-input>
    </el-form-item>
    <el-form-item label="系统奖励费" prop="rewardFee">
      <el-input v-model="dataForm.rewardFee" placeholder="系统奖励费"></el-input>
    </el-form-item>
    <el-form-item label="系统奖励规则id" prop="rewardRuleId">
      <el-input v-model="dataForm.rewardRuleId" placeholder="系统奖励规则id"></el-input>
    </el-form-item>
    <el-form-item label="优惠券金额" prop="couponAmount">
      <el-input v-model="dataForm.couponAmount" placeholder="优惠券金额"></el-input>
    </el-form-item>
    <el-form-item label="基础里程（公里）" prop="baseDistance">
      <el-input v-model="dataForm.baseDistance" placeholder="基础里程（公里）"></el-input>
    </el-form-item>
    <el-form-item label="基础里程费" prop="baseDistanceFee">
      <el-input v-model="dataForm.baseDistanceFee" placeholder="基础里程费"></el-input>
    </el-form-item>
    <el-form-item label="超出基础里程的里程（公里）" prop="exceedDistance">
      <el-input v-model="dataForm.exceedDistance" placeholder="超出基础里程的里程（公里）"></el-input>
    </el-form-item>
    <el-form-item label="超出基础里程的价格" prop="exceedDistancePrice">
      <el-input v-model="dataForm.exceedDistancePrice" placeholder="超出基础里程的价格"></el-input>
    </el-form-item>
    <el-form-item label="基础等时分钟" prop="baseWaitMinute">
      <el-input v-model="dataForm.baseWaitMinute" placeholder="基础等时分钟"></el-input>
    </el-form-item>
    <el-form-item label="超出基础等时的分钟" prop="exceedWaitMinute">
      <el-input v-model="dataForm.exceedWaitMinute" placeholder="超出基础等时的分钟"></el-input>
    </el-form-item>
    <el-form-item label="超出基础分钟的价格" prop="exceedWaitMinutePrice">
      <el-input v-model="dataForm.exceedWaitMinutePrice" placeholder="超出基础分钟的价格"></el-input>
    </el-form-item>
    <el-form-item label="基础远途里程（公里）" prop="baseLongDistance">
      <el-input v-model="dataForm.baseLongDistance" placeholder="基础远途里程（公里）"></el-input>
    </el-form-item>
    <el-form-item label="超出基础远程里程的里程" prop="exceedLongDistance">
      <el-input v-model="dataForm.exceedLongDistance" placeholder="超出基础远程里程的里程"></el-input>
    </el-form-item>
    <el-form-item label="超出基础远程里程的价格" prop="exceedLongDistancePrice">
      <el-input v-model="dataForm.exceedLongDistancePrice" placeholder="超出基础远程里程的价格"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      
<el-input v-model="dataForm.updateTime" placeholder="修改時間"></el-input>
    </el-form-item>
    <el-form-item label="是否刪除" prop="isDeleted">      <el-input v-model="dataForm.isDeleted" placeholder="是否刪除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          orderId: '',
          feeRuleId: '',
          totalAmount: '',
          payAmount: '',
          distanceFee: '',
          waitFee: '',
          longDistanceFee: '',
          tollFee: '',
          parkingFee: '',
          otherFee: '',
          favourFee: '',
          rewardFee: '',
          rewardRuleId: '',
          couponAmount: '',
          baseDistance: '',
          baseDistanceFee: '',
          exceedDistance: '',
          exceedDistancePrice: '',
          baseWaitMinute: '',
          exceedWaitMinute: '',
          exceedWaitMinutePrice: '',
          baseLongDistance: '',
          exceedLongDistance: '',
          exceedLongDistancePrice: '',
          createTime: '',
          updateTime: '',
          isDeleted: ''
        },
        dataRule: {
          orderId: [
            { required: true, message: '订单ID不能为空', trigger: 'blur' }
          ],
          feeRuleId: [
            { required: true, message: '费用规则id不能为空', trigger: 'blur' }
          ],
          totalAmount: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          payAmount: [
            { required: true, message: '应付款金额不能为空', trigger: 'blur' }
          ],
          distanceFee: [
            { required: true, message: '里程费不能为空', trigger: 'blur' }
          ],
          waitFee: [
            { required: true, message: '等时费用不能为空', trigger: 'blur' }
          ],
          longDistanceFee: [
            { required: true, message: '远程费不能为空', trigger: 'blur' }
          ],
          tollFee: [
            { required: true, message: '路桥费不能为空', trigger: 'blur' }
          ],
          parkingFee: [
            { required: true, message: '停车费不能为空', trigger: 'blur' }
          ],
          otherFee: [
            { required: true, message: '其他费用不能为空', trigger: 'blur' }
          ],
          favourFee: [
            { required: true, message: '顾客好处费不能为空', trigger: 'blur' }
          ],
          rewardFee: [
            { required: true, message: '系统奖励费不能为空', trigger: 'blur' }
          ],
          rewardRuleId: [
            { required: true, message: '系统奖励规则id不能为空', trigger: 'blur' }
          ],
          couponAmount: [
            { required: true, message: '优惠券金额不能为空', trigger: 'blur' }
          ],
          baseDistance: [
            { required: true, message: '基础里程（公里）不能为空', trigger: 'blur' }
          ],
          baseDistanceFee: [
            { required: true, message: '基础里程费不能为空', trigger: 'blur' }
          ],
          exceedDistance: [
            { required: true, message: '超出基础里程的里程（公里）不能为空', trigger: 'blur' }
          ],
          exceedDistancePrice: [
            { required: true, message: '超出基础里程的价格不能为空', trigger: 'blur' }
          ],
          baseWaitMinute: [
            { required: true, message: '基础等时分钟不能为空', trigger: 'blur' }
          ],
          exceedWaitMinute: [
            { required: true, message: '超出基础等时的分钟不能为空', trigger: 'blur' }
          ],
          exceedWaitMinutePrice: [
            { required: true, message: '超出基础分钟的价格不能为空', trigger: 'blur' }
          ],
          baseLongDistance: [
            { required: true, message: '基础远途里程（公里）不能为空', trigger: 'blur' }
          ],
          exceedLongDistance: [
            { required: true, message: '超出基础远程里程的里程不能为空', trigger: 'blur' }
          ],
          exceedLongDistancePrice: [
            { required: true, message: '超出基础远程里程的价格不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderbill/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.dataForm.orderId = data.orderBill.orderId
                this.dataForm.feeRuleId = data.orderBill.feeRuleId
                this.dataForm.totalAmount = data.orderBill.totalAmount
                this.dataForm.payAmount = data.orderBill.payAmount
                this.dataForm.distanceFee = data.orderBill.distanceFee
                this.dataForm.waitFee = data.orderBill.waitFee
                this.dataForm.longDistanceFee = data.orderBill.longDistanceFee
                this.dataForm.tollFee = data.orderBill.tollFee
                this.dataForm.parkingFee = data.orderBill.parkingFee
                this.dataForm.otherFee = data.orderBill.otherFee
                this.dataForm.favourFee = data.orderBill.favourFee
                this.dataForm.rewardFee = data.orderBill.rewardFee
                this.dataForm.rewardRuleId = data.orderBill.rewardRuleId
                this.dataForm.couponAmount = data.orderBill.couponAmount
                this.dataForm.baseDistance = data.orderBill.baseDistance
                this.dataForm.baseDistanceFee = data.orderBill.baseDistanceFee
                this.dataForm.exceedDistance = data.orderBill.exceedDistance
                this.dataForm.exceedDistancePrice = data.orderBill.exceedDistancePrice
                this.dataForm.baseWaitMinute = data.orderBill.baseWaitMinute
                this.dataForm.exceedWaitMinute = data.orderBill.exceedWaitMinute
                this.dataForm.exceedWaitMinutePrice = data.orderBill.exceedWaitMinutePrice
                this.dataForm.baseLongDistance = data.orderBill.baseLongDistance
                this.dataForm.exceedLongDistance = data.orderBill.exceedLongDistance
                this.dataForm.exceedLongDistancePrice = data.orderBill.exceedLongDistancePrice
                this.dataForm.createTime = data.orderBill.createTime
                this.dataForm.updateTime = data.orderBill.updateTime
                this.dataForm.isDeleted = data.orderBill.isDeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderbill/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'orderId': this.dataForm.orderId,
                'feeRuleId': this.dataForm.feeRuleId,
                'totalAmount': this.dataForm.totalAmount,
                'payAmount': this.dataForm.payAmount,
                'distanceFee': this.dataForm.distanceFee,
                'waitFee': this.dataForm.waitFee,
                'longDistanceFee': this.dataForm.longDistanceFee,
                'tollFee': this.dataForm.tollFee,
                'parkingFee': this.dataForm.parkingFee,
                'otherFee': this.dataForm.otherFee,
                'favourFee': this.dataForm.favourFee,
                'rewardFee': this.dataForm.rewardFee,
                'rewardRuleId': this.dataForm.rewardRuleId,
                'couponAmount': this.dataForm.couponAmount,
                'baseDistance': this.dataForm.baseDistance,
                'baseDistanceFee': this.dataForm.baseDistanceFee,
                'exceedDistance': this.dataForm.exceedDistance,
                'exceedDistancePrice': this.dataForm.exceedDistancePrice,
                'baseWaitMinute': this.dataForm.baseWaitMinute,
                'exceedWaitMinute': this.dataForm.exceedWaitMinute,
                'exceedWaitMinutePrice': this.dataForm.exceedWaitMinutePrice,
                'baseLongDistance': this.dataForm.baseLongDistance,
                'exceedLongDistance': this.dataForm.exceedLongDistance,
                'exceedLongDistancePrice': this.dataForm.exceedLongDistancePrice,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDeleted': this.dataForm.isDeleted
              })
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
